Why I am better than Freeciv's AI
This report uses a particular game to describe how I beat the AI in Freeciv, and how the AI does a horrible job when asked to take over. Foreword (2005) The report that follows was written in November, 1998, to describe how Freeciv's AI was generally doing, and to point out deficiencies. A more specific list of problems is given in a later discussion on freeciv-dev; some of them have been fixed since then, but the ones that aren't so easy to address still remain, and the Freeciv 2.0 AI still has the same overall weakness, namely, an inability to focus its efforts and apply its forces and advantages in an effective way. Introduction This game was run with Freeciv post-1.7.1, CVS version dated Oct, 24, with two patches applied: Massimo Campostrini's race extension patch and David Pfitzner's city report patch. None of these affect gameplay, but when replaying them with a standard 1.7.1 client, you will see a surprising message: Ieyasu is now ruler of the Egyptians. The AI logic is probably identical to that in vanilla 1.7.1. This small report documents its weaknesses on large maps. This document was not written as a tutorial, but as an overview of AI weaknesses. It describes a strategy that suffices to beat the AI, especially in games with high landmass. It can partly be used against human players. How I beat 11 AIs on a large map The savefiles have been taken from a single game with the following settings: set aifill 12 set xsize 70 set ysize 70 set landmass 70 set huts 50 set explorer 2 set techlevel 0 set saveturns 1 set aqueductloss 0 set scorelog 1 (The AI are hard.) The plan is practically failsafe, once you survive the initial stage. Here it is: # expand like crazy # keep cities to size 3 or 4 to avoid having to build improvements # build supply routes as the empire grows # meet approaching settlers with diplomats, convert the city as soon as it is built (cost: below 50, well worth the diplomat) # expand to defensible border zones, fill in the inland ('moyo') later # don't compete for Pyramids/Great Lib # develop Explosives (engineers!) to compensate for the Pyramids # build Michelangelo to allow city growth # continue to expand, while building up the central cities Image:Bc3800.png|3800 BC Image:Bc3360.png|3360 BC Image:Bc3260.png|3260 BC In this game, the Mongols ('nouja') are human (see 3800 BC). They conquer/subvert the Romans out of existence early on (3360 BC), even before the discovery of Republic (in 3260 BC) which neutralises most of the initial advantages (hard) AIs have over humans. After that, the Mongols have plenty of room to expand, and any human who knows the basics would find it hard to lose. However, the Americans get both Pyramids and Great Library (2340 BC), which makes for a tough opponent. Still, my plan outdevelops them easily in both size and technology, since I can quietly head for explosives (2220 BC), and build Michelangelo's Chapel (1740 BC), the wonder that usually wins the game, and that the AI are so strangely uninterested in pursuing. Image:Bc2340.png|2340 BC Image:Bc2220.png|2220 BC Image:Bc1740.png|1740 BC The date is now 1740 BC and the human is #1 in every demographic. Engineers are busy connecting the empire with railroads. My plan is to discover Electricity (to neutralize the Great Lib) and develop quietly for a while, building factories and some wonders (Shakespeare!) and taking control of the seas, while expanding steadily in Aztec territory. (Expansion is easy, thanks to the AI's ignorance of diplomats) As soon as Armor is developed, create a direct, railroaded route to the Pyramids and conquer them. Develop Robotics to allow Howitzers, because AI cities all have city walls. A patient human can conquer the world well before 1AD. Boring. Instead, I turned the Mongols to AI immediately after building Michelangelo's and observed what happened. The remaining savefiles document this: total stagnation. How the AI screws up my plan The AI immediately aborts tech development and builds city walls, barracks, and two military units in every city. With railroaded inland, two barracks and 5-10 military units suffice to counter all threats. The AI aborts the railroading. It also builds a surplus army of defensive units that spends most of its time moving about through the inland; very few ever face the enemy. Initially, I thought the AI would defend itself, and then decide to attack weaker neighbours. But it never does! It doesn't even attack enemies that are far behind in military technology. In 800 BC, for example, the Mongols have 35 Barracks II, 39 City Walls, 121 Musketeers, 9 Destroyers, and 7 Engineers. (The engineers remain from pre-AI days.) Around 5 Musketeers are being bought every turn. This pattern continues during the rest of the game. Soon after 800 BC, the Musketeers are replaced with Alpine Troops, around 150 of them. In 1100 AD, very little has changed. In 1816, finally, Robotics is discovered, but the AI never builds Howitzers! It just continues to replace Alpines with Mech Infs. Attacking units (cannon, cavalry, armor, howitzer) are hardly ever built. Concerted attacks on cities do not occur. Sometimes, a pack goes out into enemy territory. Occasionally, some of these units attack an enemy city, but mostly they just wander around. Some cities may happen to collapse when touched, but when they do, it's by coincidence. Because the AI doesn't know how to conquer, it also fails to expand outward. The Mongols have had Engineers much earlier than its competitors, but the AI never tries to capitalise on this advantage. The few engineers it had form a road net, irrigate, settle two tiny islands, add some cities in the inland area, even change grassland to forest, but they remain focused inward. No supply lines or roads into enemy territory are built. Worst of all, some inland cities still fall to the enemy! For example, the border with the French is formed by two adjacent cities that form a passage between two seas. (The AI doesn't realise this; also, it doesn't know anything about ocean topology, and happily builds destroyers on 4-tile lakes.) Between 800 BC and 200 BC, the French launch a massive attack, capture both border cities, penetrate into Mongol land and take two more cities. The Mongols, with probably twice the production and economics of the French, and way ahead in techs (Tactics vs. Gunpowder), hardly fight back! Instead, they back away from the intruders, forming a defensive line within Mongol inland territory. No attacking units are built to lash back or to recapture the inland cities. In 1871, they are still in French hands. A human defender would never allow this to happen. In 1883, some enemy cities are still in enemy hands. This is because the few (defensive) enemy units that invade are mostly left alone, and so are captured cities. The concept of counterattack is unknown, and the AI does not consider enemy cities or units right within its own inland particularly urgent targets for attack. In fact, it does not seem to consider any targets at all. When it captures a city, it's by pure chance, or because of an economically collapsing enemy that is unable to maintain basic defenses. (The Zulus, in this game.) Even in 2001, amazingly little has changed. For an overview, see the scorelog (780 BC to 2001) (gzipped), the reconstructed scorelog (3800 BC to 2001), and an animated GIF of the map, in which some more savefiles have been used. Finally, I continued the game beyond 2000 to see whether it would ever unlock into a decision. This was with a newer version ([1.7.2) which has the same AI. See the scorelog (gzipped), selected lines from the Civ I-style 'gamelog' (thanks to Jake Kesinger), the savefiles from 2051, 2101 and 2911, and two PNG screenshots from 2918. The basic picture is this: in the course of the 21th century, every grassland or plains tile is converted to desert or swamp, due to global warming. This slows down development, especially for the largest producers, the Mongols. After that, the game comes to a complete stalemate: the last city to change hands until 2918 is Axaca, in 2484. Even the weakest civilizations, still far behind in technology, lose no further terrain. Why does my human plan work against the AI? The plan exploits several of its weaknesses: * ' 'Every unit/city for itself' ' (and AI for them all ...) The AI has no conception of large 2D spaces. In managing a unit, tile, or city, it never looks farther than 3 steps away. All cities and units appear to determine their own private course of action; they hardly coordinate. The concepts of 'moyo', 'safe areas', 'defensible borders', and 'supply lines' are unknown. It never builds a road or railroad to connect two cities or areas. This is no problem on small islands (e.g. a generator 2 game). In games with larger islands, a human can claim large spaces for expansion with little defensive effort, and fill them in later; the AI may send settlers very far away, but it doesn't try to claim any good borders. * A consequence: the AI spends far too many resources defending itself. * Another consequence: the AI doesn't know how to attack cities. Attackers, if they come at all, arrive at the city one by one. Concurrent attacks with multiple units only occur by chance. This allows me to keep my military budget very low during the whole game: there will be hardly any surprises. * The AI is totally unaware of the power of subversion. It will send out single settlers without paying attention to enemy diplomats, ready to subvert the new city. Diplomats at distance 2 of a city will never be attacked; they can convert the city without any challenge. (A recent patch by Nicolas Brunel at least makes the AI build diplomats in defense.) This allows me to grow at the expense of my neighbours. Take every chance to convert an AI city, the earlier in the game the better: you will make your AI neighbour weak and paranoid, and it doesn't know how to take it back. It should also learn to use diplomats itself. * Another tactical bug: the AI hardly uses the differences in offensive vs. defensive strengths of units, or differences in speed, except in determining when to run and hide. Until recently, it routinely sent lone cannons on suicide trips to attack cities. (There is now a 'bodyguard' concept that remedies the worst.) It still doesn't realise that intruding horsemen or diplomats can be eliminated by building horsemen to counterattack. Basically, it is good on the defense and poor on the attack. * While the AI rightly chases the Pyramids and Great Library, it greatly underestimates other wonders. It doesn't seem to care about Michelangelo. It doesn't hurry to build Shakespeare, which is very powerful with railroaded supply lines (which it doesn't build either). It doesn't increase the priority of 'global' wonders over 'city-only' ones with larger games. It builds too few eternal wonders. It doesn't try to make wonders obsolete by getting the required tech. It doesn't attempt to defend cities with wonders any better than it defends other cities. * The AI doesn't weigh its opponents. I can grow big without being attacked from all sides; I can remain pathetically small and underdeveloped; the AI will never choose me as a special target. (Humans have this problem, too.) * The AI does not use ships to their full possibilities. Most ships hardly ever move in the course of their existence. Cruisers rust away in harbours when they could attack neighbouring cities. This is partly another consequence of the lack of coordination between units, and its total blindness to the topology of oceans. Also, it does not know that ships can pass through cities (the 'city canal' trick). In some games, the use of city canals can make a great difference to the power of ships and the ease of shipbuilding. The AI doesn't appear to use even two-city passages, such as the two cities bordering the French in the example game (above). * The AI doesn't clean up pollution. This takes away an incredible amount of production; in 2220 BC, Mongol production was 74; in 1883, 235; in 2001, 169! Instead, it makes matters worse by creating and railroading forests. * The AI is not aware of the possibility of flight. Helicopters are extremely effective against them. Especially the first problem and its consequences cause the stagnation. When the seams of expansion close, AIs will suddenly turn into paranoid defenders. They never build up good positions and supply lines, they never choose specific targets for attack or expansion, they just sit and defend; occasionally they send out some aimless exploration troops. Conclusion It's important to realise how strong the AI really is. Newcomers are scared (and beaten) to death by it. All of the AI code was added to Freeciv within months, by a single author, John Stonebraker. Its strengths are in the expansion phase; this report concentrates on its weaknesses, which mostly start to surface after initial expansion has finished. From this report it should be obvious that the AI needs a notion of strategy, of coordination between units and cities dispersed on a large map. I have some ideas on how to implement this, but I don't plan to do it. It also suffers from what could be called 'bugs'; the total unawareness of the power of diplomacy is probably the most obvious one because it can be exploited early in the game; such bugs can be patched up with a series of relatively simple improvements. (by nouja) Category:Gameplay